<html>
<head><meta charset="utf-8"><title>Anyone with no_std experience? · clippy · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/index.html">clippy</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html">Anyone with no_std experience?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213042749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213042749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Phil H <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213042749">(Oct 12 2020 at 14:07)</a>:</h4>
<p>Do we have someone with <code>no_std</code> experience that could review the reasoning behind a change to our <code>empty_loop</code> lint? <a href="https://github.com/rust-lang/rust-clippy/pull/6162">https://github.com/rust-lang/rust-clippy/pull/6162</a> The impl looks good to me, I just don't have any <code>no_std</code> experience to decide whether it makes sense or not.</p>



<a name="213043739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213043739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213043739">(Oct 12 2020 at 14:16)</a>:</h4>
<p>This looks good to me. But the message should be split up into the error message and the help message (<code>span_lint_and_help</code>).</p>



<a name="213085965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213085965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Henri Lunnikivi <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213085965">(Oct 12 2020 at 20:59)</a>:</h4>
<p>I'm sorry if I'm being totally obvious here, but from what I've seen it's really common that embedded applications end main with <code>loop {}</code> to prevent the main thread from exiting, while interrupt handlers do all the work. Since I don't know of any other way to do it, it must be idiomatic. It must be pretty awkward if clippy lints on an empty loop like that.</p>



<a name="213086263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213086263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213086263">(Oct 12 2020 at 21:03)</a>:</h4>
<p>maybe a better check would be if the function returns <code>!</code> and only lint when it doesn't return the never type?</p>



<a name="213086999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213086999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213086999">(Oct 12 2020 at 21:11)</a>:</h4>
<p><span class="user-mention silent" data-user-id="254983">Henri Lunnikivi</span> <a href="#narrow/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F/near/213085965">said</a>:</p>
<blockquote>
<p>I'm sorry if I'm being totally obvious here, but from what I've seen it's really common that embedded applications end main with <code>loop {}</code> to prevent the main thread from exiting, while interrupt handlers do all the work. Since I don't know of any other way to do it, it must be idiomatic. It must be pretty awkward if clippy lints on an empty loop like that.</p>
</blockquote>
<p>well that's exactly the reason for the lint</p>



<a name="213087003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213087003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213087003">(Oct 12 2020 at 21:11)</a>:</h4>
<p>currently, LLVM mis-compiles that and thinks it's UB</p>



<a name="213087023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213087023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213087023">(Oct 12 2020 at 21:11)</a>:</h4>
<p>changing not to lint on <code>loop {}</code> defeats the whole point</p>



<a name="213087130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213087130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eduardo Broto <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213087130">(Oct 12 2020 at 21:13)</a>:</h4>
<p>Yep I think Clippy should lint also in <code>no_std</code>, and add a note to the documentation. I would not change the suggestions. <code>no_std</code> users can disable the lint if they understand the consequences.</p>



<a name="213088164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213088164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dániel Buga <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213088164">(Oct 12 2020 at 21:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="254983">Henri Lunnikivi</span> <a href="#narrow/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F/near/213085965">said</a>:</p>
<blockquote>
<p>I'm sorry if I'm being totally obvious here, but from what I've seen it's really common that embedded applications end main with <code>loop {}</code> to prevent the main thread from exiting, while interrupt handlers do all the work. Since I don't know of any other way to do it, it must be idiomatic. It must be pretty awkward if clippy lints on an empty loop like that.</p>
</blockquote>
<p>To be fair, embedded systems, depending on the requirements can also sleep in an empty loop to conserve power (Some MCUs even have a sleep on exit bit so they can chose not to return to main at all). At any rate, placing a nop or whatever doesn't hurt at all, but a miscompilation kinda does <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="213120655"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213120655" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mati865 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213120655">(Oct 13 2020 at 07:43)</a>:</h4>
<p><span class="user-mention silent" data-user-id="254983">Henri Lunnikivi</span> <a href="#narrow/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F/near/213085965">said</a>:</p>
<blockquote>
<p>I'm sorry if I'm being totally obvious here, but from what I've seen it's really common that embedded applications end main with <code>loop {}</code> to prevent the main thread from exiting, while interrupt handlers do all the work. Since I don't know of any other way to do it, it must be idiomatic. It must be pretty awkward if clippy lints on an empty loop like that.</p>
</blockquote>
<p>That's exactly the problem. This is UB and can change anytime, IMO Clippy could warn (and error in the future) by default with message like "empty loops are Undefined Behaviour".</p>



<a name="213154608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213154608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213154608">(Oct 13 2020 at 13:36)</a>:</h4>
<p>well, I think we should distinguish between 'undefined behavior' and 'miscompilation'</p>



<a name="213154625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213154625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213154625">(Oct 13 2020 at 13:36)</a>:</h4>
<p>according to the rust language spec, <code>loop {}</code> is perfectly defined</p>



<a name="213154636"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213154636" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213154636">(Oct 13 2020 at 13:36)</a>:</h4>
<p>it's just miscompiled in practice</p>



<a name="213217812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213217812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mati865 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213217812">(Oct 13 2020 at 21:14)</a>:</h4>
<p>Isn't produced IR considered as UB by LLVM?</p>



<a name="213217852"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213217852" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213217852">(Oct 13 2020 at 21:14)</a>:</h4>
<p>UB is a language concept</p>



<a name="213217888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213217888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213217888">(Oct 13 2020 at 21:15)</a>:</h4>
<p>LLVM might <em>produce</em> LLVM IR that has <code>poison</code> or other invalid LLVM semantics, but it can't change what the rust spec says</p>



<a name="213234766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213234766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213234766">(Oct 14 2020 at 00:37)</a>:</h4>
<p>That's actually not how the UCG approaches the subject. UB as declared by Rust and UB as declared by LLVM are treated as separate issues.</p>



<a name="213234784"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Anyone%20with%20no_std%20experience%3F/near/213234784" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Anyone.20with.20no_std.20experience.3F.html#213234784">(Oct 14 2020 at 00:37)</a>:</h4>
<p>Particularly, because we want to have a non-llvm based rust some day, but we also currently inherit all of llvm's ub rules into rust</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>